
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>JSX · TypeScript Handbook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Patrick Zhong">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="Decorators.html" />
    
    
    <link rel="prev" href="Writing Definition Files.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="tutorials/">
            
                <a href="tutorials/">
            
                    
                    快速上手
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="tutorials/TypeScript in 5 minutes.html">
            
                <a href="tutorials/TypeScript in 5 minutes.html">
            
                    
                    5分钟了解TypeScript
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="tutorials/ASP.NET Core.html">
            
                <a href="tutorials/ASP.NET Core.html">
            
                    
                    ASP.NET Core
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="tutorials/ASP.NET 4.html">
            
                <a href="tutorials/ASP.NET 4.html">
            
                    
                    ASP.NET 4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="tutorials/Gulp.html">
            
                <a href="tutorials/Gulp.html">
            
                    
                    Gulp
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="tutorials/Knockout.html">
            
                <a href="tutorials/Knockout.html">
            
                    
                    Knockout.js
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="tutorials/React & Webpack.html">
            
                <a href="tutorials/React & Webpack.html">
            
                    
                    React与webpack
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="tutorials/React.html">
            
                <a href="tutorials/React.html">
            
                    
                    React
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="tutorials/Angular 2.html">
            
                <a href="tutorials/Angular 2.html">
            
                    
                    Angular 2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="tutorials/Migrating from JavaScript.html">
            
                <a href="tutorials/Migrating from JavaScript.html">
            
                    
                    从JavaScript迁移到TypeScript
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="./">
            
                <a href="./">
            
                    
                    手册
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="Basic Types.html">
            
                <a href="Basic Types.html">
            
                    
                    基础类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="Variable Declarations.html">
            
                <a href="Variable Declarations.html">
            
                    
                    变量声明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="Interfaces.html">
            
                <a href="Interfaces.html">
            
                    
                    接口
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="Classes.html">
            
                <a href="Classes.html">
            
                    
                    类
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="Functions.html">
            
                <a href="Functions.html">
            
                    
                    函数
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="Generics.html">
            
                <a href="Generics.html">
            
                    
                    泛型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.7" data-path="Enums.html">
            
                <a href="Enums.html">
            
                    
                    枚举
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="Type Inference.html">
            
                <a href="Type Inference.html">
            
                    
                    类型推论
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.9" data-path="Type Compatibility.html">
            
                <a href="Type Compatibility.html">
            
                    
                    类型兼容性
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.10" data-path="Advanced Types.html">
            
                <a href="Advanced Types.html">
            
                    
                    高级类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.11" data-path="Utilit Types.md">
            
                <span>
            
                    
                    实用工具类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.12" data-path="Symbols.html">
            
                <a href="Symbols.html">
            
                    
                    Symbols
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.13" data-path="Iterators and Generators.html">
            
                <a href="Iterators and Generators.html">
            
                    
                    Iterators 和 Generators
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.14" data-path="Modules.html">
            
                <a href="Modules.html">
            
                    
                    模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.15" data-path="Namespaces.html">
            
                <a href="Namespaces.html">
            
                    
                    命名空间
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.16" data-path="Namespaces and Modules.html">
            
                <a href="Namespaces and Modules.html">
            
                    
                    命名空间和模块
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.17" data-path="Module Resolution.html">
            
                <a href="Module Resolution.html">
            
                    
                    模块解析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.18" data-path="Declaration Merging.html">
            
                <a href="Declaration Merging.html">
            
                    
                    声明合并
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.19" data-path="Writing Definition Files.html">
            
                <a href="Writing Definition Files.html">
            
                    
                    书写.d.ts文件
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.20" data-path="JSX.html">
            
                <a href="JSX.html">
            
                    
                    JSX
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.21" data-path="Decorators.html">
            
                <a href="Decorators.html">
            
                    
                    Decorators
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.22" data-path="Mixins.html">
            
                <a href="Mixins.html">
            
                    
                    混入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.23" data-path="Triple-Slash Directives.html">
            
                <a href="Triple-Slash Directives.html">
            
                    
                    三斜线指令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.24" data-path="Type Checking JavaScript Files.html">
            
                <a href="Type Checking JavaScript Files.html">
            
                    
                    JavaScript文件里的类型检查
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="declaration files/Introduction.html">
            
                <a href="declaration files/Introduction.html">
            
                    
                    如何书写声明文件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="declaration files/Library Structures.html">
            
                <a href="declaration files/Library Structures.html">
            
                    
                    结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="declaration files/Do's and Don'ts.html">
            
                <a href="declaration files/Do's and Don'ts.html">
            
                    
                    规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="declaration files/By Example.html">
            
                <a href="declaration files/By Example.html">
            
                    
                    举例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="declaration files/Deep Dive.html">
            
                <a href="declaration files/Deep Dive.html">
            
                    
                    深入
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="declaration files/Publishing.html">
            
                <a href="declaration files/Publishing.html">
            
                    
                    发布
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="declaration files/Consumption.html">
            
                <a href="declaration files/Consumption.html">
            
                    
                    使用
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="tsconfig.json.html">
            
                <a href="tsconfig.json.html">
            
                    
                    工程配置
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="tsconfig.json.html">
            
                <a href="tsconfig.json.html">
            
                    
                    tsconfig.json
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="Project References.html">
            
                <a href="Project References.html">
            
                    
                    工程引用
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="Typings for NPM Packages.html">
            
                <a href="Typings for NPM Packages.html">
            
                    
                    NPM包的类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="Compiler Options.html">
            
                <a href="Compiler Options.html">
            
                    
                    编译选项
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="Configuring Watch.html">
            
                <a href="Configuring Watch.html">
            
                    
                    配置 Watch
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.6" data-path="Compiler Options in MSBuild.html">
            
                <a href="Compiler Options in MSBuild.html">
            
                    
                    在MSBuild里使用编译选项
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.7" data-path="Integrating with Build Tools.html">
            
                <a href="Integrating with Build Tools.html">
            
                    
                    与其它构建工具整合
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.8" data-path="Nightly Builds.html">
            
                <a href="Nightly Builds.html">
            
                    
                    使用TypeScript的每日构建版本
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../wiki/">
            
                <a href="../wiki/">
            
                    
                    Wiki
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../wiki/this-in-TypeScript.html">
            
                <a href="../wiki/this-in-TypeScript.html">
            
                    
                    TypeScript里的this
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../wiki/coding_guidelines.html">
            
                <a href="../wiki/coding_guidelines.html">
            
                    
                    编码规范
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="../wiki/Common Errors.html">
            
                <a href="../wiki/Common Errors.html">
            
                    
                    常见编译错误
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.4" data-path="../wiki/TypeScript-Editor-Support.html">
            
                <a href="../wiki/TypeScript-Editor-Support.html">
            
                    
                    支持TypeScript的编辑器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.5" data-path="../wiki/Using-TypeScript-With-ASP.NET-5.html">
            
                <a href="../wiki/Using-TypeScript-With-ASP.NET-5.html">
            
                    
                    结合ASP.NET v5使用TypeScript
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.6" data-path="../wiki/Architectural-Overview.html">
            
                <a href="../wiki/Architectural-Overview.html">
            
                    
                    架构概述
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.7" data-path="../wiki/Roadmap.html">
            
                <a href="../wiki/Roadmap.html">
            
                    
                    发展路线图
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../release-notes/">
            
                <a href="../release-notes/">
            
                    
                    新增功能
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../release-notes/TypeScript 3.1.html">
            
                <a href="../release-notes/TypeScript 3.1.html">
            
                    
                    TypeScript 3.1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../release-notes/TypeScript 3.0.html">
            
                <a href="../release-notes/TypeScript 3.0.html">
            
                    
                    TypeScript 3.0
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../release-notes/TypeScript 2.9.html">
            
                <a href="../release-notes/TypeScript 2.9.html">
            
                    
                    TypeScript 2.9
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../release-notes/TypeScript 2.8.html">
            
                <a href="../release-notes/TypeScript 2.8.html">
            
                    
                    TypeScript 2.8
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.5" data-path="../release-notes/TypeScript 2.7.html">
            
                <a href="../release-notes/TypeScript 2.7.html">
            
                    
                    TypeScript 2.7
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.6" data-path="../release-notes/TypeScript 2.6.html">
            
                <a href="../release-notes/TypeScript 2.6.html">
            
                    
                    TypeScript 2.6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.7" data-path="../release-notes/TypeScript 2.5.html">
            
                <a href="../release-notes/TypeScript 2.5.html">
            
                    
                    TypeScript 2.5
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.8" data-path="../release-notes/TypeScript 2.4.html">
            
                <a href="../release-notes/TypeScript 2.4.html">
            
                    
                    TypeScript 2.4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.9" data-path="../release-notes/TypeScript 2.3.html">
            
                <a href="../release-notes/TypeScript 2.3.html">
            
                    
                    TypeScript 2.3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.10" data-path="../release-notes/TypeScript 2.2.html">
            
                <a href="../release-notes/TypeScript 2.2.html">
            
                    
                    TypeScript 2.2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.11" data-path="../release-notes/TypeScript 2.1.html">
            
                <a href="../release-notes/TypeScript 2.1.html">
            
                    
                    TypeScript 2.1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.12" data-path="../release-notes/TypeScript 2.0.html">
            
                <a href="../release-notes/TypeScript 2.0.html">
            
                    
                    TypeScript 2.0
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.13" data-path="../release-notes/TypeScript 1.8.html">
            
                <a href="../release-notes/TypeScript 1.8.html">
            
                    
                    TypeScript 1.8
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.14" data-path="../release-notes/TypeScript 1.7.html">
            
                <a href="../release-notes/TypeScript 1.7.html">
            
                    
                    TypeScript 1.7
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.15" data-path="../release-notes/TypeScript 1.6.html">
            
                <a href="../release-notes/TypeScript 1.6.html">
            
                    
                    TypeScript 1.6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.16" data-path="../release-notes/TypeScript 1.5.html">
            
                <a href="../release-notes/TypeScript 1.5.html">
            
                    
                    TypeScript 1.5
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.17" data-path="../release-notes/TypeScript 1.4.html">
            
                <a href="../release-notes/TypeScript 1.4.html">
            
                    
                    TypeScript 1.4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.18" data-path="../release-notes/TypeScript 1.3.html">
            
                <a href="../release-notes/TypeScript 1.3.html">
            
                    
                    TypeScript 1.3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.19" data-path="../release-notes/TypeScript 1.1.html">
            
                <a href="../release-notes/TypeScript 1.1.html">
            
                    
                    TypeScript 1.1
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../breaking-changes/breaking-changes.html">
            
                <a href="../breaking-changes/breaking-changes.html">
            
                    
                    Breaking Changes
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../breaking-changes/TypeScript 2.4.html">
            
                <a href="../breaking-changes/TypeScript 2.4.html">
            
                    
                    TypeScript 2.4
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../breaking-changes/TypeScript 2.3.html">
            
                <a href="../breaking-changes/TypeScript 2.3.html">
            
                    
                    TypeScript 2.3
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../breaking-changes/TypeScript 2.2.html">
            
                <a href="../breaking-changes/TypeScript 2.2.html">
            
                    
                    TypeScript 2.2
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../breaking-changes/TypeScript 2.1.html">
            
                <a href="../breaking-changes/TypeScript 2.1.html">
            
                    
                    TypeScript 2.1
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.5" data-path="../breaking-changes/TypeScript 2.0.html">
            
                <a href="../breaking-changes/TypeScript 2.0.html">
            
                    
                    TypeScript 2.0
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.6" data-path="../breaking-changes/TypeScript 1.8.html">
            
                <a href="../breaking-changes/TypeScript 1.8.html">
            
                    
                    TypeScript 1.8
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.7" data-path="../breaking-changes/TypeScript 1.7.html">
            
                <a href="../breaking-changes/TypeScript 1.7.html">
            
                    
                    TypeScript 1.7
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.8" data-path="../breaking-changes/TypeScript 1.6.html">
            
                <a href="../breaking-changes/TypeScript 1.6.html">
            
                    
                    TypeScript 1.6
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.9" data-path="../breaking-changes/TypeScript 1.5.html">
            
                <a href="../breaking-changes/TypeScript 1.5.html">
            
                    
                    TypeScript 1.5
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.10" data-path="../breaking-changes/TypeScript 1.4.html">
            
                <a href="../breaking-changes/TypeScript 1.4.html">
            
                    
                    TypeScript 1.4
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >JSX</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x4ECB;&#x7ECD;">&#x4ECB;&#x7ECD;</h1>
<p><a href="https://facebook.github.io/jsx/" target="_blank">JSX</a>&#x662F;&#x4E00;&#x79CD;&#x5D4C;&#x5165;&#x5F0F;&#x7684;&#x7C7B;&#x4F3C;XML&#x7684;&#x8BED;&#x6CD5;&#x3002;
&#x5B83;&#x53EF;&#x4EE5;&#x88AB;&#x8F6C;&#x6362;&#x6210;&#x5408;&#x6CD5;&#x7684;JavaScript&#xFF0C;&#x5C3D;&#x7BA1;&#x8F6C;&#x6362;&#x7684;&#x8BED;&#x4E49;&#x662F;&#x4F9D;&#x636E;&#x4E0D;&#x540C;&#x7684;&#x5B9E;&#x73B0;&#x800C;&#x5B9A;&#x7684;&#x3002;
JSX&#x56E0;<a href="https://reactjs.org/" target="_blank">React</a>&#x6846;&#x67B6;&#x800C;&#x6D41;&#x884C;&#xFF0C;&#x4F46;&#x4E5F;&#x5B58;&#x5728;&#x5176;&#x5B83;&#x7684;&#x5B9E;&#x73B0;&#x3002;
TypeScript&#x652F;&#x6301;&#x5185;&#x5D4C;&#xFF0C;&#x7C7B;&#x578B;&#x68C0;&#x67E5;&#x4EE5;&#x53CA;&#x5C06;JSX&#x76F4;&#x63A5;&#x7F16;&#x8BD1;&#x4E3A;JavaScript&#x3002;</p>
<h1 id="&#x57FA;&#x672C;&#x7528;&#x6CD5;">&#x57FA;&#x672C;&#x7528;&#x6CD5;</h1>
<p>&#x60F3;&#x8981;&#x4F7F;&#x7528;JSX&#x5FC5;&#x987B;&#x505A;&#x4E24;&#x4EF6;&#x4E8B;&#xFF1A;</p>
<ol>
<li>&#x7ED9;&#x6587;&#x4EF6;&#x4E00;&#x4E2A;<code>.tsx</code>&#x6269;&#x5C55;&#x540D;</li>
<li>&#x542F;&#x7528;<code>jsx</code>&#x9009;&#x9879;</li>
</ol>
<p>TypeScript&#x5177;&#x6709;&#x4E09;&#x79CD;JSX&#x6A21;&#x5F0F;&#xFF1A;<code>preserve</code>&#xFF0C;<code>react</code>&#x548C;<code>react-native</code>&#x3002;
&#x8FD9;&#x4E9B;&#x6A21;&#x5F0F;&#x53EA;&#x5728;&#x4EE3;&#x7801;&#x751F;&#x6210;&#x9636;&#x6BB5;&#x8D77;&#x4F5C;&#x7528; - &#x7C7B;&#x578B;&#x68C0;&#x67E5;&#x5E76;&#x4E0D;&#x53D7;&#x5F71;&#x54CD;&#x3002;
&#x5728;<code>preserve</code>&#x6A21;&#x5F0F;&#x4E0B;&#x751F;&#x6210;&#x4EE3;&#x7801;&#x4E2D;&#x4F1A;&#x4FDD;&#x7559;JSX&#x4EE5;&#x4F9B;&#x540E;&#x7EED;&#x7684;&#x8F6C;&#x6362;&#x64CD;&#x4F5C;&#x4F7F;&#x7528;&#xFF08;&#x6BD4;&#x5982;&#xFF1A;<a href="https://babeljs.io/" target="_blank">Babel</a>&#xFF09;&#x3002;
&#x53E6;&#x5916;&#xFF0C;&#x8F93;&#x51FA;&#x6587;&#x4EF6;&#x4F1A;&#x5E26;&#x6709;<code>.jsx</code>&#x6269;&#x5C55;&#x540D;&#x3002;
<code>react</code>&#x6A21;&#x5F0F;&#x4F1A;&#x751F;&#x6210;<code>React.createElement</code>&#xFF0C;&#x5728;&#x4F7F;&#x7528;&#x524D;&#x4E0D;&#x9700;&#x8981;&#x518D;&#x8FDB;&#x884C;&#x8F6C;&#x6362;&#x64CD;&#x4F5C;&#x4E86;&#xFF0C;&#x8F93;&#x51FA;&#x6587;&#x4EF6;&#x7684;&#x6269;&#x5C55;&#x540D;&#x4E3A;<code>.js</code>&#x3002;
<code>react-native</code>&#x76F8;&#x5F53;&#x4E8E;<code>preserve</code>&#xFF0C;&#x5B83;&#x4E5F;&#x4FDD;&#x7559;&#x4E86;&#x6240;&#x6709;&#x7684;JSX&#xFF0C;&#x4F46;&#x662F;&#x8F93;&#x51FA;&#x6587;&#x4EF6;&#x7684;&#x6269;&#x5C55;&#x540D;&#x662F;<code>.js</code>&#x3002;</p>
<table>
<thead>
<tr>
<th>&#x6A21;&#x5F0F;</th>
<th>&#x8F93;&#x5165;</th>
<th>&#x8F93;&#x51FA;</th>
<th>&#x8F93;&#x51FA;&#x6587;&#x4EF6;&#x6269;&#x5C55;&#x540D;</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>preserve</code></td>
<td><code>&lt;div /&gt;</code></td>
<td><code>&lt;div /&gt;</code></td>
<td><code>.jsx</code></td>
</tr>
<tr>
<td><code>react</code></td>
<td><code>&lt;div /&gt;</code></td>
<td><code>React.createElement(&quot;div&quot;)</code></td>
<td><code>.js</code></td>
</tr>
<tr>
<td><code>react-native</code></td>
<td><code>&lt;div /&gt;</code></td>
<td><code>&lt;div /&gt;</code></td>
<td><code>.js</code></td>
</tr>
</tbody>
</table>
<p>&#x4F60;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x5728;&#x547D;&#x4EE4;&#x884C;&#x91CC;&#x4F7F;&#x7528;<code>--jsx</code>&#x6807;&#x8BB0;&#x6216;<a href="tsconfig.json.html">tsconfig.json</a>&#x91CC;&#x7684;&#x9009;&#x9879;&#x6765;&#x6307;&#x5B9A;&#x6A21;&#x5F0F;&#x3002;</p>
<blockquote>
<p><em>&#x6CE8;&#x610F;&#xFF1A;<code>React</code>&#x6807;&#x8BC6;&#x7B26;&#x662F;&#x5199;&#x6B7B;&#x7684;&#x786C;&#x7F16;&#x7801;&#xFF0C;&#x6240;&#x4EE5;&#x4F60;&#x5FC5;&#x987B;&#x4FDD;&#x8BC1;React&#xFF08;&#x5927;&#x5199;&#x7684;R&#xFF09;&#x662F;&#x53EF;&#x7528;&#x7684;&#x3002;</em></p>
</blockquote>
<h1 id="as&#x64CD;&#x4F5C;&#x7B26;"><code>as</code>&#x64CD;&#x4F5C;&#x7B26;</h1>
<p>&#x56DE;&#x60F3;&#x4E00;&#x4E0B;&#x600E;&#x4E48;&#x5199;&#x7C7B;&#x578B;&#x65AD;&#x8A00;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">var</span> foo = &lt;foo&gt;bar;
</code></pre>
<p>&#x8FD9;&#x91CC;&#x65AD;&#x8A00;<code>bar</code>&#x53D8;&#x91CF;&#x662F;<code>foo</code>&#x7C7B;&#x578B;&#x7684;&#x3002;
&#x56E0;&#x4E3A;TypeScript&#x4E5F;&#x4F7F;&#x7528;&#x5C16;&#x62EC;&#x53F7;&#x6765;&#x8868;&#x793A;&#x7C7B;&#x578B;&#x65AD;&#x8A00;&#xFF0C;&#x5728;&#x7ED3;&#x5408;JSX&#x7684;&#x8BED;&#x6CD5;&#x540E;&#x5C06;&#x5E26;&#x6765;&#x89E3;&#x6790;&#x4E0A;&#x7684;&#x56F0;&#x96BE;&#x3002;&#x56E0;&#x6B64;&#xFF0C;TypeScript&#x5728;<code>.tsx</code>&#x6587;&#x4EF6;&#x91CC;&#x7981;&#x7528;&#x4E86;&#x4F7F;&#x7528;&#x5C16;&#x62EC;&#x53F7;&#x7684;&#x7C7B;&#x578B;&#x65AD;&#x8A00;&#x3002;</p>
<p>&#x7531;&#x4E8E;&#x4E0D;&#x80FD;&#x591F;&#x5728;<code>.tsx</code>&#x6587;&#x4EF6;&#x91CC;&#x4F7F;&#x7528;&#x4E0A;&#x8FF0;&#x8BED;&#x6CD5;&#xFF0C;&#x56E0;&#x6B64;&#x6211;&#x4EEC;&#x5E94;&#x8BE5;&#x4F7F;&#x7528;&#x53E6;&#x4E00;&#x4E2A;&#x7C7B;&#x578B;&#x65AD;&#x8A00;&#x64CD;&#x4F5C;&#x7B26;&#xFF1A;<code>as</code>&#x3002;
&#x4E0A;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x53EF;&#x4EE5;&#x5F88;&#x5BB9;&#x6613;&#x5730;&#x4F7F;&#x7528;<code>as</code>&#x64CD;&#x4F5C;&#x7B26;&#x6539;&#x5199;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">var</span> foo = bar as foo;
</code></pre>
<p><code>as</code>&#x64CD;&#x4F5C;&#x7B26;&#x5728;<code>.ts</code>&#x548C;<code>.tsx</code>&#x91CC;&#x90FD;&#x53EF;&#x7528;&#xFF0C;&#x5E76;&#x4E14;&#x4E0E;&#x5C16;&#x62EC;&#x53F7;&#x7C7B;&#x578B;&#x65AD;&#x8A00;&#x884C;&#x4E3A;&#x662F;&#x7B49;&#x4EF7;&#x7684;&#x3002;</p>
<h1 id="&#x7C7B;&#x578B;&#x68C0;&#x67E5;">&#x7C7B;&#x578B;&#x68C0;&#x67E5;</h1>
<p>&#x4E3A;&#x4E86;&#x7406;&#x89E3;JSX&#x7684;&#x7C7B;&#x578B;&#x68C0;&#x67E5;&#xFF0C;&#x4F60;&#x5FC5;&#x987B;&#x9996;&#x5148;&#x7406;&#x89E3;&#x56FA;&#x6709;&#x5143;&#x7D20;&#x4E0E;&#x57FA;&#x4E8E;&#x503C;&#x7684;&#x5143;&#x7D20;&#x4E4B;&#x95F4;&#x7684;&#x533A;&#x522B;&#x3002;
&#x5047;&#x8BBE;&#x6709;&#x8FD9;&#x6837;&#x4E00;&#x4E2A;JSX&#x8868;&#x8FBE;&#x5F0F;<code>&lt;expr /&gt;</code>&#xFF0C;<code>expr</code>&#x53EF;&#x80FD;&#x5F15;&#x7528;&#x73AF;&#x5883;&#x81EA;&#x5E26;&#x7684;&#x67D0;&#x4E9B;&#x4E1C;&#x897F;&#xFF08;&#x6BD4;&#x5982;&#xFF0C;&#x5728;DOM&#x73AF;&#x5883;&#x91CC;&#x7684;<code>div</code>&#x6216;<code>span</code>&#xFF09;&#x6216;&#x8005;&#x662F;&#x4F60;&#x81EA;&#x5B9A;&#x4E49;&#x7684;&#x7EC4;&#x4EF6;&#x3002;
&#x8FD9;&#x662F;&#x975E;&#x5E38;&#x91CD;&#x8981;&#x7684;&#xFF0C;&#x539F;&#x56E0;&#x6709;&#x5982;&#x4E0B;&#x4E24;&#x70B9;&#xFF1A;</p>
<ol>
<li>&#x5BF9;&#x4E8E;React&#xFF0C;&#x56FA;&#x6709;&#x5143;&#x7D20;&#x4F1A;&#x751F;&#x6210;&#x5B57;&#x7B26;&#x4E32;&#xFF08;<code>React.createElement(&quot;div&quot;)</code>&#xFF09;&#xFF0C;&#x7136;&#x800C;&#x7531;&#x4F60;&#x81EA;&#x5B9A;&#x4E49;&#x7684;&#x7EC4;&#x4EF6;&#x5374;&#x4E0D;&#x4F1A;&#x751F;&#x6210;&#xFF08;<code>React.createElement(MyComponent)</code>&#xFF09;&#x3002;</li>
<li>&#x4F20;&#x5165;JSX&#x5143;&#x7D20;&#x91CC;&#x7684;&#x5C5E;&#x6027;&#x7C7B;&#x578B;&#x7684;&#x67E5;&#x627E;&#x65B9;&#x5F0F;&#x4E0D;&#x540C;&#x3002;
&#x56FA;&#x6709;&#x5143;&#x7D20;&#x5C5E;&#x6027;<em>&#x672C;&#x8EAB;</em>&#x5C31;&#x652F;&#x6301;&#xFF0C;&#x7136;&#x800C;&#x81EA;&#x5B9A;&#x4E49;&#x7684;&#x7EC4;&#x4EF6;&#x4F1A;&#x81EA;&#x5DF1;&#x53BB;&#x6307;&#x5B9A;&#x5B83;&#x4EEC;&#x5177;&#x6709;&#x54EA;&#x4E2A;&#x5C5E;&#x6027;&#x3002;</li>
</ol>
<p>TypeScript&#x4F7F;&#x7528;<a href="http://facebook.github.io/react/docs/jsx-in-depth.html#html-tags-vs.-react-components" target="_blank">&#x4E0E;React&#x76F8;&#x540C;&#x7684;&#x89C4;&#x8303;</a> &#x6765;&#x533A;&#x522B;&#x5B83;&#x4EEC;&#x3002;
&#x56FA;&#x6709;&#x5143;&#x7D20;&#x603B;&#x662F;&#x4EE5;&#x4E00;&#x4E2A;&#x5C0F;&#x5199;&#x5B57;&#x6BCD;&#x5F00;&#x5934;&#xFF0C;&#x57FA;&#x4E8E;&#x503C;&#x7684;&#x5143;&#x7D20;&#x603B;&#x662F;&#x4EE5;&#x4E00;&#x4E2A;&#x5927;&#x5199;&#x5B57;&#x6BCD;&#x5F00;&#x5934;&#x3002;</p>
<h2 id="&#x56FA;&#x6709;&#x5143;&#x7D20;">&#x56FA;&#x6709;&#x5143;&#x7D20;</h2>
<p>&#x56FA;&#x6709;&#x5143;&#x7D20;&#x4F7F;&#x7528;&#x7279;&#x6B8A;&#x7684;&#x63A5;&#x53E3;<code>JSX.IntrinsicElements</code>&#x6765;&#x67E5;&#x627E;&#x3002;
&#x9ED8;&#x8BA4;&#x5730;&#xFF0C;&#x5982;&#x679C;&#x8FD9;&#x4E2A;&#x63A5;&#x53E3;&#x6CA1;&#x6709;&#x6307;&#x5B9A;&#xFF0C;&#x4F1A;&#x5168;&#x90E8;&#x901A;&#x8FC7;&#xFF0C;&#x4E0D;&#x5BF9;&#x56FA;&#x6709;&#x5143;&#x7D20;&#x8FDB;&#x884C;&#x7C7B;&#x578B;&#x68C0;&#x67E5;&#x3002;
&#x7136;&#x800C;&#xFF0C;&#x5982;&#x679C;&#x8FD9;&#x4E2A;&#x63A5;&#x53E3;&#x5B58;&#x5728;&#xFF0C;&#x90A3;&#x4E48;&#x56FA;&#x6709;&#x5143;&#x7D20;&#x7684;&#x540D;&#x5B57;&#x9700;&#x8981;&#x5728;<code>JSX.IntrinsicElements</code>&#x63A5;&#x53E3;&#x7684;&#x5C5E;&#x6027;&#x91CC;&#x67E5;&#x627E;&#x3002;
&#x4F8B;&#x5982;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">declare</span> <span class="hljs-keyword">namespace</span> JSX {
    <span class="hljs-keyword">interface</span> IntrinsicElements {
        foo: <span class="hljs-built_in">any</span>
    }
}

&lt;foo /&gt;; <span class="hljs-comment">// &#x6B63;&#x786E;</span>
&lt;bar /&gt;; <span class="hljs-comment">// &#x9519;&#x8BEF;</span>
</code></pre>
<p>&#x5728;&#x4E0A;&#x4F8B;&#x4E2D;&#xFF0C;<code>&lt;foo /&gt;</code>&#x6CA1;&#x6709;&#x95EE;&#x9898;&#xFF0C;&#x4F46;&#x662F;<code>&lt;bar /&gt;</code>&#x4F1A;&#x62A5;&#x9519;&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x6CA1;&#x5728;<code>JSX.IntrinsicElements</code>&#x91CC;&#x6307;&#x5B9A;&#x3002;</p>
<blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x4F60;&#x4E5F;&#x53EF;&#x4EE5;&#x5728;<code>JSX.IntrinsicElements</code>&#x4E0A;&#x6307;&#x5B9A;&#x4E00;&#x4E2A;&#x7528;&#x6765;&#x6355;&#x83B7;&#x6240;&#x6709;&#x5B57;&#x7B26;&#x4E32;&#x7D22;&#x5F15;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">declare</span> <span class="hljs-keyword">namespace</span> JSX {
   <span class="hljs-keyword">interface</span> IntrinsicElements {
       [elemName: <span class="hljs-built_in">string</span>]: <span class="hljs-built_in">any</span>;
   }
}
</code></pre>
</blockquote>
<h2 id="&#x57FA;&#x4E8E;&#x503C;&#x7684;&#x5143;&#x7D20;">&#x57FA;&#x4E8E;&#x503C;&#x7684;&#x5143;&#x7D20;</h2>
<p>&#x57FA;&#x4E8E;&#x503C;&#x7684;&#x5143;&#x7D20;&#x4F1A;&#x7B80;&#x5355;&#x7684;&#x5728;&#x5B83;&#x6240;&#x5728;&#x7684;&#x4F5C;&#x7528;&#x57DF;&#x91CC;&#x6309;&#x6807;&#x8BC6;&#x7B26;&#x67E5;&#x627E;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> MyComponent from <span class="hljs-string">&quot;./myComponent&quot;</span>;

&lt;MyComponent /&gt;; <span class="hljs-comment">// &#x6B63;&#x786E;</span>
&lt;SomeOtherComponent /&gt;; <span class="hljs-comment">// &#x9519;&#x8BEF;</span>
</code></pre>
<p>&#x6709;&#x4E24;&#x79CD;&#x65B9;&#x5F0F;&#x53EF;&#x4EE5;&#x5B9A;&#x4E49;&#x57FA;&#x4E8E;&#x503C;&#x7684;&#x5143;&#x7D20;&#xFF1A;</p>
<ol>
<li>&#x65E0;&#x72B6;&#x6001;&#x51FD;&#x6570;&#x7EC4;&#x4EF6; (SFC)</li>
<li>&#x7C7B;&#x7EC4;&#x4EF6;</li>
</ol>
<p>&#x7531;&#x4E8E;&#x8FD9;&#x4E24;&#x79CD;&#x57FA;&#x4E8E;&#x503C;&#x7684;&#x5143;&#x7D20;&#x5728;JSX&#x8868;&#x8FBE;&#x5F0F;&#x91CC;&#x65E0;&#x6CD5;&#x533A;&#x5206;&#xFF0C;&#x56E0;&#x6B64;TypeScript&#x9996;&#x5148;&#x4F1A;&#x5C1D;&#x8BD5;&#x5C06;&#x8868;&#x8FBE;&#x5F0F;&#x505A;&#x4E3A;&#x65E0;&#x72B6;&#x6001;&#x51FD;&#x6570;&#x7EC4;&#x4EF6;&#x8FDB;&#x884C;&#x89E3;&#x6790;&#x3002;&#x5982;&#x679C;&#x89E3;&#x6790;&#x6210;&#x529F;&#xFF0C;&#x90A3;&#x4E48;TypeScript&#x5C31;&#x5B8C;&#x6210;&#x4E86;&#x8868;&#x8FBE;&#x5F0F;&#x5230;&#x5176;&#x58F0;&#x660E;&#x7684;&#x89E3;&#x6790;&#x64CD;&#x4F5C;&#x3002;&#x5982;&#x679C;&#x6309;&#x7167;&#x65E0;&#x72B6;&#x6001;&#x51FD;&#x6570;&#x7EC4;&#x4EF6;&#x89E3;&#x6790;&#x5931;&#x8D25;&#xFF0C;&#x90A3;&#x4E48;TypeScript&#x4F1A;&#x7EE7;&#x7EED;&#x5C1D;&#x8BD5;&#x4EE5;&#x7C7B;&#x7EC4;&#x4EF6;&#x7684;&#x5F62;&#x5F0F;&#x8FDB;&#x884C;&#x89E3;&#x6790;&#x3002;&#x5982;&#x679C;&#x4F9D;&#x65E7;&#x5931;&#x8D25;&#xFF0C;&#x90A3;&#x4E48;&#x5C06;&#x8F93;&#x51FA;&#x4E00;&#x4E2A;&#x9519;&#x8BEF;&#x3002;</p>
<h3 id="&#x65E0;&#x72B6;&#x6001;&#x51FD;&#x6570;&#x7EC4;&#x4EF6;">&#x65E0;&#x72B6;&#x6001;&#x51FD;&#x6570;&#x7EC4;&#x4EF6;</h3>
<p>&#x6B63;&#x5982;&#x5176;&#x540D;&#xFF0C;&#x7EC4;&#x4EF6;&#x88AB;&#x5B9A;&#x4E49;&#x6210;JavaScript&#x51FD;&#x6570;&#xFF0C;&#x5B83;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x662F;<code>props</code>&#x5BF9;&#x8C61;&#x3002;
TypeScript&#x4F1A;&#x5F3A;&#x5236;&#x5B83;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x53EF;&#x4EE5;&#x8D4B;&#x503C;&#x7ED9;<code>JSX.Element</code>&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">interface</span> FooProp {
  name: <span class="hljs-built_in">string</span>;
  X: <span class="hljs-built_in">number</span>;
  Y: <span class="hljs-built_in">number</span>;
}

<span class="hljs-keyword">declare</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">AnotherComponent</span>(<span class="hljs-params">prop: {name: <span class="hljs-built_in">string</span>}</span>)</span>;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">ComponentFoo</span>(<span class="hljs-params">prop: FooProp</span>) </span>{
  <span class="hljs-keyword">return</span> &lt;AnotherComponent name={prop.name} /&gt;;
}

<span class="hljs-keyword">const</span> Button = (prop: {value: <span class="hljs-built_in">string</span>}, context: { color: <span class="hljs-built_in">string</span> }) =&gt; &lt;button&gt;
</code></pre>
<p>&#x7531;&#x4E8E;&#x65E0;&#x72B6;&#x6001;&#x51FD;&#x6570;&#x7EC4;&#x4EF6;&#x662F;&#x7B80;&#x5355;&#x7684;JavaScript&#x51FD;&#x6570;&#xFF0C;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x8FD8;&#x53EF;&#x4EE5;&#x5229;&#x7528;&#x51FD;&#x6570;&#x91CD;&#x8F7D;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">interface</span> ClickableProps {
  children: JSX.Element[] | JSX.Element
}

<span class="hljs-keyword">interface</span> HomeProps <span class="hljs-keyword">extends</span> ClickableProps {
  home: JSX.Element;
}

<span class="hljs-keyword">interface</span> SideProps <span class="hljs-keyword">extends</span> ClickableProps {
  side: JSX.Element | <span class="hljs-built_in">string</span>;
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">MainButton</span>(<span class="hljs-params">prop: HomeProps</span>): <span class="hljs-title">JSX</span>.<span class="hljs-title">Element</span></span>;
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">MainButton</span>(<span class="hljs-params">prop: SideProps</span>): <span class="hljs-title">JSX</span>.<span class="hljs-title">Element</span> </span>{
  ...
}
</code></pre>
<h3 id="&#x7C7B;&#x7EC4;&#x4EF6;">&#x7C7B;&#x7EC4;&#x4EF6;</h3>
<p>&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5B9A;&#x4E49;&#x7C7B;&#x7EC4;&#x4EF6;&#x7684;&#x7C7B;&#x578B;&#x3002;
&#x7136;&#x800C;&#xFF0C;&#x6211;&#x4EEC;&#x9996;&#x5148;&#x6700;&#x597D;&#x5F04;&#x61C2;&#x4E24;&#x4E2A;&#x65B0;&#x7684;&#x672F;&#x8BED;&#xFF1A;<em>&#x5143;&#x7D20;&#x7C7B;&#x7684;&#x7C7B;&#x578B;</em>&#x548C;<em>&#x5143;&#x7D20;&#x5B9E;&#x4F8B;&#x7684;&#x7C7B;&#x578B;</em>&#x3002;</p>
<p>&#x73B0;&#x5728;&#x6709;<code>&lt;Expr /&gt;</code>&#xFF0C;<em>&#x5143;&#x7D20;&#x7C7B;&#x7684;&#x7C7B;&#x578B;</em>&#x4E3A;<code>Expr</code>&#x7684;&#x7C7B;&#x578B;&#x3002;
&#x6240;&#x4EE5;&#x5728;&#x4E0A;&#x9762;&#x7684;&#x4F8B;&#x5B50;&#x91CC;&#xFF0C;&#x5982;&#x679C;<code>MyComponent</code>&#x662F;ES6&#x7684;&#x7C7B;&#xFF0C;&#x90A3;&#x4E48;&#x7C7B;&#x7C7B;&#x578B;&#x5C31;&#x662F;&#x7C7B;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;&#x548C;&#x9759;&#x6001;&#x90E8;&#x5206;&#x3002;
&#x5982;&#x679C;<code>MyComponent</code>&#x662F;&#x4E2A;&#x5DE5;&#x5382;&#x51FD;&#x6570;&#xFF0C;&#x7C7B;&#x7C7B;&#x578B;&#x4E3A;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x3002;</p>
<p>&#x4E00;&#x65E6;&#x5EFA;&#x7ACB;&#x8D77;&#x4E86;&#x7C7B;&#x7C7B;&#x578B;&#xFF0C;&#x5B9E;&#x4F8B;&#x7C7B;&#x578B;&#x7531;&#x7C7B;&#x6784;&#x9020;&#x5668;&#x6216;&#x8C03;&#x7528;&#x7B7E;&#x540D;&#xFF08;&#x5982;&#x679C;&#x5B58;&#x5728;&#x7684;&#x8BDD;&#xFF09;&#x7684;&#x8FD4;&#x56DE;&#x503C;&#x7684;&#x8054;&#x5408;&#x6784;&#x6210;&#x3002;
&#x518D;&#x6B21;&#x8BF4;&#x660E;&#xFF0C;&#x5728;ES6&#x7C7B;&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x5B9E;&#x4F8B;&#x7C7B;&#x578B;&#x4E3A;&#x8FD9;&#x4E2A;&#x7C7B;&#x7684;&#x5B9E;&#x4F8B;&#x7684;&#x7C7B;&#x578B;&#xFF0C;&#x5E76;&#x4E14;&#x5982;&#x679C;&#x662F;&#x5DE5;&#x5382;&#x51FD;&#x6570;&#xFF0C;&#x5B9E;&#x4F8B;&#x7C7B;&#x578B;&#x4E3A;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">class</span> MyComponent {
  render() {}
}

<span class="hljs-comment">// &#x4F7F;&#x7528;&#x6784;&#x9020;&#x7B7E;&#x540D;</span>
<span class="hljs-keyword">var</span> myComponent = <span class="hljs-keyword">new</span> MyComponent();

<span class="hljs-comment">// &#x5143;&#x7D20;&#x7C7B;&#x7684;&#x7C7B;&#x578B; =&gt; MyComponent</span>
<span class="hljs-comment">// &#x5143;&#x7D20;&#x5B9E;&#x4F8B;&#x7684;&#x7C7B;&#x578B; =&gt; { render: () =&gt; void }</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">MyFactoryFunction</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> {
    render: () =&gt; {
    }
  }
}

<span class="hljs-comment">// &#x4F7F;&#x7528;&#x8C03;&#x7528;&#x7B7E;&#x540D;</span>
<span class="hljs-keyword">var</span> myComponent = MyFactoryFunction();

<span class="hljs-comment">// &#x5143;&#x7D20;&#x7C7B;&#x7684;&#x7C7B;&#x578B; =&gt; FactoryFunction</span>
<span class="hljs-comment">// &#x5143;&#x7D20;&#x5B9E;&#x4F8B;&#x7684;&#x7C7B;&#x578B; =&gt; { render: () =&gt; void }</span>
</code></pre>
<p>&#x5143;&#x7D20;&#x7684;&#x5B9E;&#x4F8B;&#x7C7B;&#x578B;&#x5F88;&#x6709;&#x8DA3;&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x5FC5;&#x987B;&#x8D4B;&#x503C;&#x7ED9;<code>JSX.ElementClass</code>&#x6216;&#x629B;&#x51FA;&#x4E00;&#x4E2A;&#x9519;&#x8BEF;&#x3002;
&#x9ED8;&#x8BA4;&#x7684;<code>JSX.ElementClass</code>&#x4E3A;<code>{}</code>&#xFF0C;&#x4F46;&#x662F;&#x5B83;&#x53EF;&#x4EE5;&#x88AB;&#x6269;&#x5C55;&#x7528;&#x6765;&#x9650;&#x5236;JSX&#x7684;&#x7C7B;&#x578B;&#x4EE5;&#x7B26;&#x5408;&#x76F8;&#x5E94;&#x7684;&#x63A5;&#x53E3;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">declare</span> <span class="hljs-keyword">namespace</span> JSX {
  <span class="hljs-keyword">interface</span> ElementClass {
    render: <span class="hljs-built_in">any</span>;
  }
}

<span class="hljs-keyword">class</span> MyComponent {
  render() {}
}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">MyFactoryFunction</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> { render: () =&gt; {} }
}

&lt;MyComponent /&gt;; <span class="hljs-comment">// &#x6B63;&#x786E;</span>
&lt;MyFactoryFunction /&gt;; <span class="hljs-comment">// &#x6B63;&#x786E;</span>

<span class="hljs-keyword">class</span> NotAValidComponent {}
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">NotAValidFactoryFunction</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> {};
}

&lt;NotAValidComponent /&gt;; <span class="hljs-comment">// &#x9519;&#x8BEF;</span>
&lt;NotAValidFactoryFunction /&gt;; <span class="hljs-comment">// &#x9519;&#x8BEF;</span>
</code></pre>
<h2 id="&#x5C5E;&#x6027;&#x7C7B;&#x578B;&#x68C0;&#x67E5;">&#x5C5E;&#x6027;&#x7C7B;&#x578B;&#x68C0;&#x67E5;</h2>
<p>&#x5C5E;&#x6027;&#x7C7B;&#x578B;&#x68C0;&#x67E5;&#x7684;&#x7B2C;&#x4E00;&#x6B65;&#x662F;&#x786E;&#x5B9A;<em>&#x5143;&#x7D20;&#x5C5E;&#x6027;&#x7C7B;&#x578B;</em>&#x3002;
&#x8FD9;&#x5728;&#x56FA;&#x6709;&#x5143;&#x7D20;&#x548C;&#x57FA;&#x4E8E;&#x503C;&#x7684;&#x5143;&#x7D20;&#x4E4B;&#x95F4;&#x7A0D;&#x6709;&#x4E0D;&#x540C;&#x3002;</p>
<p>&#x5BF9;&#x4E8E;&#x56FA;&#x6709;&#x5143;&#x7D20;&#xFF0C;&#x8FD9;&#x662F;<code>JSX.IntrinsicElements</code>&#x5C5E;&#x6027;&#x7684;&#x7C7B;&#x578B;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">declare</span> <span class="hljs-keyword">namespace</span> JSX {
  <span class="hljs-keyword">interface</span> IntrinsicElements {
    foo: { bar?: <span class="hljs-built_in">boolean</span> }
  }
}

<span class="hljs-comment">// `foo`&#x7684;&#x5143;&#x7D20;&#x5C5E;&#x6027;&#x7C7B;&#x578B;&#x4E3A;`{bar?: boolean}`</span>
&lt;foo bar /&gt;;
</code></pre>
<p>&#x5BF9;&#x4E8E;&#x57FA;&#x4E8E;&#x503C;&#x7684;&#x5143;&#x7D20;&#xFF0C;&#x5C31;&#x7A0D;&#x5FAE;&#x590D;&#x6742;&#x4E9B;&#x3002;
&#x5B83;&#x53D6;&#x51B3;&#x4E8E;&#x5148;&#x524D;&#x786E;&#x5B9A;&#x7684;&#x5728;&#x5143;&#x7D20;&#x5B9E;&#x4F8B;&#x7C7B;&#x578B;&#x4E0A;&#x7684;&#x67D0;&#x4E2A;&#x5C5E;&#x6027;&#x7684;&#x7C7B;&#x578B;&#x3002;
&#x81F3;&#x4E8E;&#x8BE5;&#x4F7F;&#x7528;&#x54EA;&#x4E2A;&#x5C5E;&#x6027;&#x6765;&#x786E;&#x5B9A;&#x7C7B;&#x578B;&#x53D6;&#x51B3;&#x4E8E;<code>JSX.ElementAttributesProperty</code>&#x3002;
&#x5B83;&#x5E94;&#x8BE5;&#x4F7F;&#x7528;&#x5355;&#x4E00;&#x7684;&#x5C5E;&#x6027;&#x6765;&#x5B9A;&#x4E49;&#x3002;
&#x8FD9;&#x4E2A;&#x5C5E;&#x6027;&#x540D;&#x4E4B;&#x540E;&#x4F1A;&#x88AB;&#x4F7F;&#x7528;&#x3002;
TypeScript 2.8&#xFF0C;&#x5982;&#x679C;&#x672A;&#x6307;&#x5B9A;<code>JSX.ElementAttributesProperty</code>&#xFF0C;&#x90A3;&#x4E48;&#x5C06;&#x4F7F;&#x7528;&#x7C7B;&#x5143;&#x7D20;&#x6784;&#x9020;&#x51FD;&#x6570;&#x6216;SFC&#x8C03;&#x7528;&#x7684;&#x7B2C;&#x4E00;&#x4E2A;&#x53C2;&#x6570;&#x7684;&#x7C7B;&#x578B;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">declare</span> <span class="hljs-keyword">namespace</span> JSX {
  <span class="hljs-keyword">interface</span> ElementAttributesProperty {
    props; <span class="hljs-comment">// &#x6307;&#x5B9A;&#x7528;&#x6765;&#x4F7F;&#x7528;&#x7684;&#x5C5E;&#x6027;&#x540D;</span>
  }
}

<span class="hljs-keyword">class</span> MyComponent {
  <span class="hljs-comment">// &#x5728;&#x5143;&#x7D20;&#x5B9E;&#x4F8B;&#x7C7B;&#x578B;&#x4E0A;&#x6307;&#x5B9A;&#x5C5E;&#x6027;</span>
  props: {
    foo?: <span class="hljs-built_in">string</span>;
  }
}

<span class="hljs-comment">// `MyComponent`&#x7684;&#x5143;&#x7D20;&#x5C5E;&#x6027;&#x7C7B;&#x578B;&#x4E3A;`{foo?: string}`</span>
&lt;MyComponent foo=<span class="hljs-string">&quot;bar&quot;</span> /&gt;
</code></pre>
<p>&#x5143;&#x7D20;&#x5C5E;&#x6027;&#x7C7B;&#x578B;&#x7528;&#x4E8E;&#x7684;JSX&#x91CC;&#x8FDB;&#x884C;&#x5C5E;&#x6027;&#x7684;&#x7C7B;&#x578B;&#x68C0;&#x67E5;&#x3002;
&#x652F;&#x6301;&#x53EF;&#x9009;&#x5C5E;&#x6027;&#x548C;&#x5FC5;&#x987B;&#x5C5E;&#x6027;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">declare</span> <span class="hljs-keyword">namespace</span> JSX {
  <span class="hljs-keyword">interface</span> IntrinsicElements {
    foo: { requiredProp: <span class="hljs-built_in">string</span>; optionalProp?: <span class="hljs-built_in">number</span> }
  }
}

&lt;foo requiredProp=<span class="hljs-string">&quot;bar&quot;</span> /&gt;; <span class="hljs-comment">// &#x6B63;&#x786E;</span>
&lt;foo requiredProp=<span class="hljs-string">&quot;bar&quot;</span> optionalProp={<span class="hljs-number">0</span>} /&gt;; <span class="hljs-comment">// &#x6B63;&#x786E;</span>
&lt;foo /&gt;; <span class="hljs-comment">// &#x9519;&#x8BEF;, &#x7F3A;&#x5C11; requiredProp</span>
&lt;foo requiredProp={<span class="hljs-number">0</span>} /&gt;; <span class="hljs-comment">// &#x9519;&#x8BEF;, requiredProp &#x5E94;&#x8BE5;&#x662F;&#x5B57;&#x7B26;&#x4E32;</span>
&lt;foo requiredProp=<span class="hljs-string">&quot;bar&quot;</span> unknownProp /&gt;; <span class="hljs-comment">// &#x9519;&#x8BEF;, unknownProp &#x4E0D;&#x5B58;&#x5728;</span>
&lt;foo requiredProp=<span class="hljs-string">&quot;bar&quot;</span> some-unknown-prop /&gt;; <span class="hljs-comment">// &#x6B63;&#x786E;, `some-unknown-prop`&#x4E0D;&#x662F;&#x4E2A;&#x5408;&#x6CD5;&#x7684;&#x6807;&#x8BC6;&#x7B26;</span>
</code></pre>
<blockquote>
<p>&#x6CE8;&#x610F;&#xFF1A;&#x5982;&#x679C;&#x4E00;&#x4E2A;&#x5C5E;&#x6027;&#x540D;&#x4E0D;&#x662F;&#x4E2A;&#x5408;&#x6CD5;&#x7684;JS&#x6807;&#x8BC6;&#x7B26;&#xFF08;&#x50CF;<code>data-*</code>&#x5C5E;&#x6027;&#xFF09;&#xFF0C;&#x5E76;&#x4E14;&#x5B83;&#x6CA1;&#x51FA;&#x73B0;&#x5728;&#x5143;&#x7D20;&#x5C5E;&#x6027;&#x7C7B;&#x578B;&#x91CC;&#x65F6;&#x4E0D;&#x4F1A;&#x5F53;&#x505A;&#x4E00;&#x4E2A;&#x9519;&#x8BEF;&#x3002;</p>
</blockquote>
<p>&#x53E6;&#x5916;&#xFF0C;JSX&#x8FD8;&#x4F1A;&#x4F7F;&#x7528;<code>JSX.IntrinsicAttributes</code>&#x63A5;&#x53E3;&#x6765;&#x6307;&#x5B9A;&#x989D;&#x5916;&#x7684;&#x5C5E;&#x6027;&#xFF0C;&#x8FD9;&#x4E9B;&#x989D;&#x5916;&#x7684;&#x5C5E;&#x6027;&#x901A;&#x5E38;&#x4E0D;&#x4F1A;&#x88AB;&#x7EC4;&#x4EF6;&#x7684;props&#x6216;arguments&#x4F7F;&#x7528; - &#x6BD4;&#x5982;React&#x91CC;&#x7684;<code>key</code>&#x3002;&#x8FD8;&#x6709;&#xFF0C;<code>JSX.IntrinsicClassAttributes&lt;T&gt;</code>&#x6CDB;&#x578B;&#x7C7B;&#x578B;&#x4E5F;&#x53EF;&#x4EE5;&#x7528;&#x6765;&#x505A;&#x540C;&#x6837;&#x7684;&#x4E8B;&#x60C5;&#x3002;&#x8FD9;&#x91CC;&#x7684;&#x6CDB;&#x578B;&#x53C2;&#x6570;&#x8868;&#x793A;&#x7C7B;&#x5B9E;&#x4F8B;&#x7C7B;&#x578B;&#x3002;&#x5728;React&#x91CC;&#xFF0C;&#x5B83;&#x7528;&#x6765;&#x5141;&#x8BB8;<code>Ref&lt;T&gt;</code>&#x7C7B;&#x578B;&#x4E0A;&#x7684;<code>ref</code>&#x5C5E;&#x6027;&#x3002;&#x901A;&#x5E38;&#x6765;&#x8BB2;&#xFF0C;&#x8FD9;&#x4E9B;&#x63A5;&#x53E3;&#x4E0A;&#x7684;&#x6240;&#x6709;&#x5C5E;&#x6027;&#x90FD;&#x662F;&#x53EF;&#x9009;&#x7684;&#xFF0C;&#x9664;&#x975E;&#x4F60;&#x60F3;&#x8981;&#x7528;&#x6237;&#x5728;&#x6BCF;&#x4E2A;JSX&#x6807;&#x7B7E;&#x4E0A;&#x90FD;&#x63D0;&#x4F9B;&#x4E00;&#x4E9B;&#x5C5E;&#x6027;&#x3002;</p>
<p>&#x5EF6;&#x5C55;&#x64CD;&#x4F5C;&#x7B26;&#x4E5F;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;&#xFF1A;</p>
<pre><code class="lang-JSX"><span class="hljs-keyword">var</span> props = { requiredProp: <span class="hljs-string">&apos;bar&apos;</span> };
&lt;foo {...props} /&gt;; // &#x6B63;&#x786E;

var badProps = {};
&lt;foo {...badProps} /&gt;; // &#x9519;&#x8BEF;
</code></pre>
<h2 id="&#x5B50;&#x5B59;&#x7C7B;&#x578B;&#x68C0;&#x67E5;">&#x5B50;&#x5B59;&#x7C7B;&#x578B;&#x68C0;&#x67E5;</h2>
<p>&#x4ECE;TypeScript 2.3&#x5F00;&#x59CB;&#xFF0C;&#x6211;&#x4EEC;&#x5F15;&#x5165;&#x4E86;<em>children</em>&#x7C7B;&#x578B;&#x68C0;&#x67E5;&#x3002;<em>children</em>&#x662F;<em>&#x5143;&#x7D20;&#x5C5E;&#x6027;(attribute)&#x7C7B;&#x578B;</em>&#x7684;&#x4E00;&#x4E2A;&#x7279;&#x6B8A;&#x5C5E;&#x6027;(property)&#xFF0C;&#x5B50;<em>JSXExpression</em>&#x5C06;&#x4F1A;&#x88AB;&#x63D2;&#x5165;&#x5230;&#x5C5E;&#x6027;&#x91CC;&#x3002;
&#x4E0E;&#x4F7F;&#x7528;<code>JSX.ElementAttributesProperty</code>&#x6765;&#x51B3;&#x5B9A;<em>props</em>&#x540D;&#x7C7B;&#x4F3C;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x5229;&#x7528;<code>JSX.ElementChildrenAttribute</code>&#x6765;&#x51B3;&#x5B9A;<em>children</em>&#x540D;&#x3002;
<code>JSX.ElementChildrenAttribute</code>&#x5E94;&#x8BE5;&#x88AB;&#x58F0;&#x660E;&#x5728;&#x5355;&#x4E00;&#x7684;&#x5C5E;&#x6027;(property)&#x91CC;&#x3002;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">declare</span> <span class="hljs-keyword">namespace</span> JSX {
  <span class="hljs-keyword">interface</span> ElementChildrenAttribute {
    children: {};  <span class="hljs-comment">// specify children name to use</span>
  }
}
</code></pre>
<p>&#x5982;&#x4E0D;&#x7279;&#x6B8A;&#x6307;&#x5B9A;&#x5B50;&#x5B59;&#x7684;&#x7C7B;&#x578B;&#xFF0C;&#x6211;&#x4EEC;&#x5C06;&#x4F7F;&#x7528;<a href="https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react" target="_blank">React typings</a>&#x91CC;&#x7684;&#x9ED8;&#x8BA4;&#x7C7B;&#x578B;&#x3002;</p>
<pre><code class="lang-ts">&lt;div&gt;
  &lt;h1&gt;Hello&lt;/h1&gt;
&lt;/div&gt;;

&lt;div&gt;
  &lt;h1&gt;Hello&lt;/h1&gt;
  World
&lt;/div&gt;;

const CustomComp = (props) =&gt; &lt;div&gt;props.children&lt;/div&gt;
&lt;CustomComp&gt;
  &lt;div&gt;Hello World&lt;/div&gt;
  {&quot;This is just a JS expression...&quot; + 1000}
&lt;/CustomComp&gt;
</code></pre>
<pre><code class="lang-ts">interface PropsType {
  children: JSX.Element
  name: string
}

class Component extends React.Component&lt;PropsType, {}&gt; {
  render() {
    return (
      &lt;h2&gt;
        {this.props.children}
      &lt;/h2&gt;
    )
  }
}

// OK
&lt;Component&gt;
  &lt;h1&gt;Hello World&lt;/h1&gt;
&lt;/Component&gt;

// Error: children is of type JSX.Element not array of JSX.Element
&lt;Component&gt;
  &lt;h1&gt;Hello World&lt;/h1&gt;
  &lt;h2&gt;Hello World&lt;/h2&gt;
&lt;/Component&gt;

// Error: children is of type JSX.Element not array of JSX.Element or string.
&lt;Component&gt;
  &lt;h1&gt;Hello&lt;/h1&gt;
  World
&lt;/Component&gt;
</code></pre>
<h1 id="jsx&#x7ED3;&#x679C;&#x7C7B;&#x578B;">JSX&#x7ED3;&#x679C;&#x7C7B;&#x578B;</h1>
<p>&#x9ED8;&#x8BA4;&#x5730;JSX&#x8868;&#x8FBE;&#x5F0F;&#x7ED3;&#x679C;&#x7684;&#x7C7B;&#x578B;&#x4E3A;<code>any</code>&#x3002;
&#x4F60;&#x53EF;&#x4EE5;&#x81EA;&#x5B9A;&#x4E49;&#x8FD9;&#x4E2A;&#x7C7B;&#x578B;&#xFF0C;&#x901A;&#x8FC7;&#x6307;&#x5B9A;<code>JSX.Element</code>&#x63A5;&#x53E3;&#x3002;
&#x7136;&#x800C;&#xFF0C;&#x4E0D;&#x80FD;&#x591F;&#x4ECE;&#x63A5;&#x53E3;&#x91CC;&#x68C0;&#x7D22;&#x5143;&#x7D20;&#xFF0C;&#x5C5E;&#x6027;&#x6216;JSX&#x7684;&#x5B50;&#x5143;&#x7D20;&#x7684;&#x7C7B;&#x578B;&#x4FE1;&#x606F;&#x3002;
&#x5B83;&#x662F;&#x4E00;&#x4E2A;&#x9ED1;&#x76D2;&#x3002;</p>
<h1 id="&#x5D4C;&#x5165;&#x7684;&#x8868;&#x8FBE;&#x5F0F;">&#x5D4C;&#x5165;&#x7684;&#x8868;&#x8FBE;&#x5F0F;</h1>
<p>JSX&#x5141;&#x8BB8;&#x4F60;&#x4F7F;&#x7528;<code>{ }</code>&#x6807;&#x7B7E;&#x6765;&#x5185;&#x5D4C;&#x8868;&#x8FBE;&#x5F0F;&#x3002;</p>
<pre><code class="lang-JSX"><span class="hljs-keyword">var</span> a = <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
  {[&apos;foo&apos;, &apos;bar&apos;].map(i =&gt; <span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>{i / 2}<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>)}
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x4EA7;&#x751F;&#x4E00;&#x4E2A;&#x9519;&#x8BEF;&#xFF0C;&#x56E0;&#x4E3A;&#x4F60;&#x4E0D;&#x80FD;&#x7528;&#x6570;&#x5B57;&#x6765;&#x9664;&#x4EE5;&#x4E00;&#x4E2A;&#x5B57;&#x7B26;&#x4E32;&#x3002;
&#x8F93;&#x51FA;&#x5982;&#x4E0B;&#xFF0C;&#x82E5;&#x4F60;&#x4F7F;&#x7528;&#x4E86;<code>preserve</code>&#x9009;&#x9879;&#xFF1A;</p>
<pre><code class="lang-JSX"><span class="hljs-keyword">var</span> a = <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
  {[&apos;foo&apos;, &apos;bar&apos;].map(function (i) { return <span class="hljs-tag">&lt;<span class="hljs-name">span</span>&gt;</span>{i / 2}<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>; })}
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
</code></pre>
<h1 id="react&#x6574;&#x5408;">React&#x6574;&#x5408;</h1>
<p>&#x8981;&#x60F3;&#x4E00;&#x8D77;&#x4F7F;&#x7528;JSX&#x548C;React&#xFF0C;&#x4F60;&#x5E94;&#x8BE5;&#x4F7F;&#x7528;<a href="https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react" target="_blank">React&#x7C7B;&#x578B;&#x5B9A;&#x4E49;</a>&#x3002;
&#x8FD9;&#x4E9B;&#x7C7B;&#x578B;&#x58F0;&#x660E;&#x5B9A;&#x4E49;&#x4E86;<code>JSX</code>&#x5408;&#x9002;&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x6765;&#x4F7F;&#x7528;React&#x3002;</p>
<pre><code class="lang-ts">/// &lt;reference path=&quot;react.d.ts&quot; /&gt;

interface Props {
  foo: string;
}

class MyComponent extends React.Component&lt;Props, {}&gt; {
  render() {
    return &lt;span&gt;{this.props.foo}&lt;/span&gt;
  }
}

&lt;MyComponent foo=&quot;bar&quot; /&gt;; // &#x6B63;&#x786E;
&lt;MyComponent foo={0} /&gt;; // &#x9519;&#x8BEF;
</code></pre>
<h1 id="&#x5DE5;&#x5382;&#x51FD;&#x6570;">&#x5DE5;&#x5382;&#x51FD;&#x6570;</h1>
<p><code>jsx: react</code>&#x7F16;&#x8BD1;&#x9009;&#x9879;&#x4F7F;&#x7528;&#x7684;&#x5DE5;&#x5382;&#x51FD;&#x6570;&#x662F;&#x53EF;&#x4EE5;&#x914D;&#x7F6E;&#x7684;&#x3002;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;<code>jsxFactory</code>&#x547D;&#x4EE4;&#x884C;&#x9009;&#x9879;&#xFF0C;&#x6216;&#x5185;&#x8054;&#x7684;<code>@jsx</code>&#x6CE8;&#x91CA;&#x6307;&#x4EE4;&#x5728;&#x6BCF;&#x4E2A;&#x6587;&#x4EF6;&#x4E0A;&#x8BBE;&#x7F6E;&#x3002;&#x6BD4;&#x5982;&#xFF0C;&#x7ED9;<code>createElement</code>&#x8BBE;&#x7F6E;<code>jsxFactory</code>&#xFF0C;<code>&lt;div /&gt;</code>&#x4F1A;&#x4F7F;&#x7528;<code>createElement(&quot;div&quot;)</code>&#x6765;&#x751F;&#x6210;&#xFF0C;&#x800C;&#x4E0D;&#x662F;<code>React.createElement(&quot;div&quot;)</code>&#x3002;</p>
<p>&#x6CE8;&#x91CA;&#x6307;&#x4EE4;&#x53EF;&#x4EE5;&#x50CF;&#x4E0B;&#x9762;&#x8FD9;&#x6837;&#x4F7F;&#x7528;&#xFF08;&#x5728;TypeScript 2.8&#x91CC;&#xFF09;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">import</span> preact = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;preact&quot;</span>);
<span class="hljs-comment">/* @jsx preact.h */</span>
<span class="hljs-keyword">const</span> x = &lt;div /&gt;;
</code></pre>
<p>&#x751F;&#x6210;&#xFF1A;</p>
<pre><code class="lang-ts"><span class="hljs-keyword">const</span> preact = <span class="hljs-built_in">require</span>(<span class="hljs-string">&quot;preact&quot;</span>);
<span class="hljs-keyword">const</span> x = preact.h(<span class="hljs-string">&quot;div&quot;</span>, <span class="hljs-literal">null</span>);
</code></pre>
<p>&#x5DE5;&#x5382;&#x51FD;&#x6570;&#x7684;&#x9009;&#x62E9;&#x540C;&#x6837;&#x4F1A;&#x5F71;&#x54CD;<code>JSX</code>&#x547D;&#x540D;&#x7A7A;&#x95F4;&#x7684;&#x67E5;&#x627E;&#xFF08;&#x7C7B;&#x578B;&#x68C0;&#x67E5;&#xFF09;&#x3002;&#x5982;&#x679C;&#x5DE5;&#x5382;&#x51FD;&#x6570;&#x4F7F;&#x7528;<code>React.createElement</code>&#x5B9A;&#x4E49;&#xFF08;&#x9ED8;&#x8BA4;&#xFF09;&#xFF0C;&#x7F16;&#x8BD1;&#x5668;&#x4F1A;&#x5148;&#x68C0;&#x67E5;<code>React.JSX</code>&#xFF0C;&#x4E4B;&#x540E;&#x624D;&#x68C0;&#x67E5;&#x5168;&#x5C40;&#x7684;<code>JSX</code>&#x3002;&#x5982;&#x679C;&#x5DE5;&#x5382;&#x51FD;&#x6570;&#x5B9A;&#x4E49;&#x4E3A;<code>h</code>&#xFF0C;&#x90A3;&#x4E48;&#x5728;&#x68C0;&#x67E5;&#x5168;&#x5C40;&#x7684;<code>JSX</code>&#x4E4B;&#x524D;&#x5148;&#x68C0;&#x67E5;<code>h.JSX</code>&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="Writing Definition Files.html" class="navigation navigation-prev " aria-label="Previous page: 书写.d.ts文件">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="Decorators.html" class="navigation navigation-next " aria-label="Next page: Decorators">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"JSX","level":"1.3.20","depth":2,"next":{"title":"Decorators","level":"1.3.21","depth":2,"path":"doc/handbook/Decorators.md","ref":"./doc/handbook/Decorators.md","articles":[]},"previous":{"title":"书写.d.ts文件","level":"1.3.19","depth":2,"path":"doc/handbook/Writing Definition Files.md","ref":"./doc/handbook/Writing Definition Files.md","articles":[]},"dir":"ltr"},"config":{"plugins":[],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"Patrick Zhong","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"preface.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"TypeScript Handbook","language":"zh-hans","gitbook":">3.0.0","description":"Translation of official TypeScript Handbook"},"file":{"path":"doc/handbook/JSX.md","mtime":"2018-10-13T09:48:54.000Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-10-13T09:57:42.904Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

